package com.youlai.system.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.system.common.base.BaseQuery;
import com.youlai.system.model.entity.SysScore;
import com.youlai.system.model.form.ScoreForm;
import com.youlai.system.model.query.ScorePageQuery;
import com.youlai.system.model.query.UserScoreCountPageQuery;
import com.youlai.system.model.vo.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 课程成绩业务接口
 */
public interface SysScoreService extends IService<SysScore> {

    /**
     * @param checkDate
     * @param studentId
     * @param courseId
     * @return
     */
    SysScore getBy(String checkDate, Long studentId, Long courseId);


    /**
     * @param checkDate
     * @param checkTime
     * @param studentId
     * @param courseId
     * @return
     */
    SysScore getBy(String checkDate, String checkTime, Long studentId, Long courseId);

    /**
     * 成绩分页列表
     *
     * @return
     */
    IPage<ScorePageVO> getScorePage(ScorePageQuery queryParams);

    List<ScorePageVO> getScoreListByIdList(List<Long> scoreIdList);

    /**
     * 学生成绩统计分页列表
     *
     * @param queryParams
     * @return
     */
    IPage<UserScoreCountPageVO> getUserScoreCountPage(UserScoreCountPageQuery queryParams);

    /**
     * 查询某个学生的故障成绩汇总情况
     *
     * @param userId
     * @return
     */
    List<UserCourseScoreCountVO> getUserCourseScoreCountList(Long userId);

    /**
     * 查询某个学生的故障分类成绩汇总情况
     *
     * @param userId
     * @return
     */
    List<UserCategoryScoreCountVO> getUserCategoryScoreCountList(Long userId);

    /**
     * 保存成绩
     *
     * @param scoreForm
     * @return
     */
    boolean saveScore(Long studentId, ScoreForm scoreForm);

    /**
     * 更新成绩
     *
     * @param scoreForm
     * @return
     */
    boolean updateScore(Long scoreId, Long studentId, ScoreForm scoreForm);

    /**
     * 查询单个成绩
     *
     * @param scoreId
     * @return
     */
    ScoreForm getScoreForm(Long scoreId);

    /**
     * 删除成绩列表
     *
     * @param idsStr
     * @return
     */
    boolean deleteScores(String idsStr);


    List<CategoryScoreCountVO> getAllCategoryScoreCountList();

    Map<Long, CategoryScoreCountVO> getAllCategoryScoreCountMap();

    List<CourseScoreCountVO> getAllCourseScoreCountList(BaseQuery baseQuery);

    Map<Long, CourseScoreCountVO> getAllCourseScoreCountMap();

    List<LocationScoreCountVO> getAllLocationScoreCountList(BaseQuery baseQuery);

    Map<Long, LocationScoreCountVO> getAllLocationScoreCountMap();

    List<MeasureScoreCountVO> getAllMeasureScoreCountList(BaseQuery baseQuery);

    Map<Long, MeasureScoreCountVO> getAllMeasureScoreCountMap();

    List<QuestionScoreCountVO> getAllQuestionScoreCountList(BaseQuery baseQuery);

    Map<Long, QuestionScoreCountVO> getAllQuestionScoreCountMap();

    boolean courseHasUsed(List<Long> courseIdList);

    boolean locationHasUsed(List<Long> locationIdList);

    boolean measureHasUsed(List<Long> measureIdList);

    boolean questionHasUsed(List<Long> questionIdList);

    boolean userHasUsed(List<Long> userIdList);


    Long scorePassCount(BaseQuery baseQuery);

    /**
     * 根据培训司机ID和故障ID查询成绩按照考试倒序排序列表
     *
     * @param userId
     * @param courseId
     * @return
     */
    List<SysScore> get4ScoreList(Long userId, Long courseId);

    /**
     * 根据培训司机ID和故障ID查询成绩按照考试倒序排序列表
     *
     * @param userId
     * @param courseId
     * @param number
     * @return
     */
    List<SysScore> getNumScoreList(Long userId, Long courseId, Integer number);

    /**
     * @param userId
     * @param courseId
     * @return
     */
    SysScore getMinOneScore(Long userId, Long courseId);

    /**
     * 根据培训司机ID和故障ID查询成绩按照考试倒序排序列表
     *
     * @param userId
     * @param courseId
     * @return
     */
    List<SysScore> getScoreList(Long userId, Long courseId, LocalDateTime maxTime);


    /**
     * 根据培训司机ID和故障ID查询初级定级用到的成绩按照考试倒序排序列表
     *
     * @param userId
     * @param courseId
     * @param maxTime
     * @return
     */
    List<SysScore> getPrimaryDegreeScoreList(Long userId, Long courseId, LocalDateTime maxTime);


    /**
     * @param userId
     * @param scoreIdList
     * @return
     */
    List<SysScore> getPrimayPeriodScoreList(Long userId, List<Long> scoreIdList);


    boolean updateHasUsedToZero(Long studentId, Long courseId);


    boolean updateHasUsedToZeroByCourseId(Long courseId);


    Long countByStudentIdAndCourseId(Long studentId, Long courseId);

}
